/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';

/**
 * 单号源列表
 */
// 获取第三方单号源
export async function getThird(params) {
  return request('/common/WaybillSource/third', {
    method: 'POST',
    data: params,
  });
}

// 签约快递员列表
export async function getAgree(params) {
  return request('/common/WaybillSource/agree', {
    method: 'POST',
    data: params,
  });
}

// 大客户授权列表
export async function getKop(params) {
  return request('/common/WaybillSource/kop', {
    method: 'POST',
    data: params,
  });
}
// 快递员自有面单列表
export async function getCourier(params) {
  return request('/common/WaybillSource/courier', {
    method: 'POST',
    data: params,
  });
}
// 77商家权列表
export async function getBranch(params) {
  return request('/common/WaybillSource/branch', {
    method: 'POST',
    data: params,
  });
}

// 团队分享单号源
export async function getGroup(params) {
  return request('/common/WaybillSource/group', {
    method: 'POST',
    data: params,
  });
}

// 大客户品牌列表
export async function getKopBrand(params) {
  return request('/Api/orderManage/WaybillSource/kopBrandList', {
    method: 'POST',
    data: params,
  });
}

// 快递员自有面单
// 获取验证码
export async function getCaptcha(params) {
  return request('/common/SourceAccount/getCode', {
    method: 'POST',
    data: params,
  });
}

// 77商家搜索
export async function searchBranch(params) {
  return request('/common/SourceAccount/searchBranch', {
    method: 'POST',
    data: params,
  });
}

// 根据工号获取快递员信息
export async function getCourierInfo(params) {
  return request('/common/SourceAccount/getCourierInfo', {
    method: 'POST',
    data: params,
  });
}
// 单号源授权
const authAPI = {
  kop: '/Api/orderManage/WaybillSource/companyAuth',  // 大客户授权
  branch: '/common/SourceAccount/bindBranch',
  courier: '/common/SourceAccount/bindCourier',
  taobao: '/Api/orderManage/WaybillSource/getThirdAuthUrl',
  wuliuyun: '/Api/orderManage/WaybillSource/getThirdAuthUrl',
  wuliuyun_token: '/Api/orderManage/WaybillSource/tokenAuth',
  pindd: '/Api/orderManage/WaybillSource/pddMerchant',
  pdd_universal: '/Api/orderManage/WaybillSource/pddUniversal',
  yz:'/web/ThirdAuth/yz',
  wd:'/web/ThirdAuth/wd',
};
export async function auth(params, kind) {
  const url = authAPI[kind];
  if (!url) {
    return new Promise(resolve => {
      resolve({ code: 1, msg: '无效操作' });
    });
  }
  return request(url, {
    method: 'POST',
    body: params,
  });
}

// 单号源取消
export async function cancel(params) {
  const url = "/Api/orderManage/WaybillSource/delAuthInfo";
  if (!url) {
    return new Promise(resolve => {
      resolve({ code: 1, msg: '无效操作' });
    });
  }
  return request(url, {
    method: 'POST',
    body: params,
  });
}

// 获取所有单号源
export async function getAllSource(params) {
  return request('/Api/orderManage/WaybillSource/alreadyList', {
    method: 'POST',
    body: params,
  });
}


// 第三方授权
const thirdUrl = {
  pindd:'/web/ThirdAuth/pddOrderUrl',
  yz:'/web/ThirdAuth/yz',
  yz2:'/web/ThirdAuth/yz2',
  wd:'/web/ThirdAuth/wd',
  wm:'/web/ThirdAuth/wm',
  ks:'/web/ThirdAuth/ks',
}
export async function authThirdOrder(params) {
  const url = thirdUrl[params.key];
  if (!url) {
    return new Promise(resolve => {
      resolve({ code: 1, msg: '无效操作' });
    });
  }
  return request(url, {
    method: 'POST',
    body: params,
  });
}
